//
//  EJSFeedbackViewController.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2017/12/14.
//  Copyright © 2017年 lifayu. All rights reserved.
//

#import "EJSFeedbackViewController.h"
#import "UIPlaceHolderTextView.h"
#import "EJSFeedbackRequest.h"

@interface EJSFeedbackViewController ()
@property (weak, nonatomic) IBOutlet UITextField *titleTextField;
@property (weak, nonatomic) IBOutlet UILimitTextView *contentTextView;

@end

@implementation EJSFeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"意见反馈";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)configOwnViews
{
    self.contentTextView.placeHolder = @"请输入您的反馈意见~";
    
    UIView *view = [UIView new];
    view.frame = CGRectMake(0, 0, 10, 40);
    self.titleTextField.leftView = view;
    self.titleTextField.leftViewMode = UITextFieldViewModeAlways;
    self.titleTextField.rightView = view;
    self.titleTextField.rightViewMode = UITextFieldViewModeAlways;
}

- (IBAction)submitAction:(UIButton *)sender{
    NSString *title = self.titleTextField.text;
    if(!title || title.length == 0){
        [[HUDHelper sharedInstance] tipMessage:@"请输入标题"];
        return;
    }
    NSString *content = self.contentTextView.text;
    if(!content || content.length == 0){
        [[HUDHelper sharedInstance] tipMessage:@"请输入您的反馈意见~"];
        return;
    }
    
    EJSFeedbackRequest *req = [EJSFeedbackRequest new];
    req.title = title;
    req.content = content;
    [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
        
        [HUDHelper alertTitle:@"提示" message:@"感谢您宝贵的建议，我们将在第一时间与您联系" cancel:@"确认" action:^{
            [self leftBarButtonAction:nil];
        }];
    } failHandler:^(BaseResponse *response) {
        [[HUDHelper sharedInstance] tipMessage:response.message];
    }];
}

@end

